@layout('layouts.system')

@section('content')

<div class="page-header">
    <h3>{{Str::title(__('global.report').' '.__('admin.attendance'))}}</h3>
</div>
<div class="row-fluids">
	<div class="span12">
	{{ Form::vertical_open('report/jasper/integrate', 'POST', array('id' => 'genReport')) }}
	<div class="row-fluids">
		<div class="span12">
			<div class="control-group">
				<label class="control-label" for="fullname">Jenis Laporan</label>
				<div class="controls">
				{{ Form::span10_select('report', $reports),'',Form::inline_help('&nbsp;<span class="text-error"><strong>*</strong><small>'.__('global.required')->get().'</small></span>'); }}
				</div>
			</div>
		</div>
	</div>
	<div class="row-fluids">
		<div class="span12">
	<div class="row-fluids">
		<div class="span6">
			<div class="control-group">
				<label class="control-label" for="fullname">{{ Str::title(__('admin.groupno')->get()) }}</label>
				<div class="controls">
					<!--{{ Form::xlarge_select('wjkp_no_auto', $kumpulan, $profile->wjkp_no_auto); }}-->
					{{ Form::xlarge_select('wjkp_no_auto', $kumpulan, (Auth::user()->sur_id != 1)?$profile->wjkp_no_auto:''); }}
				</div>
			</div>
			<div class="control-group">
				<label class="control-label" for="fullname">{{ Str::title(__('admin.department')->get()) }}</label>
				<div class="controls">
					<!--{{ Form::xlarge_select('wpj_no_auto', $jabatan, $profile->wpj_no_auto); }}-->
					{{ Form::xlarge_select('wpj_no_auto', $jabatan, (Auth::user()->sur_id != 1)?$profile->wpj_no_auto:''); }}
				</div>
			</div>
			<div class="control-group">
				<label class="control-label" for="fullname">{{ Str::title(__('admin.division')->get()) }}</label>
				<div class="controls">
					<!--{{ Form::xlarge_select('wpb_no_auto', $bahagian, $profile->wpb_no_auto); }}-->
					{{ Form::xlarge_select('wpb_no_auto', $bahagian, (Auth::user()->sur_id != 1)?$profile->wpb_no_auto:''); }}
				</div>
			</div>
			<div class="control-group">
				<label class="control-label" for="fullname">{{ Str::title(__('admin.unit')->get()) }}</label>
				<div class="controls">
					<!--{{ Form::xlarge_select('wpu_no_auto', $unit, $profile->wpu_no_auto); }}-->
					{{ Form::xlarge_select('wpu_no_auto', $unit, (Auth::user()->sur_id != 1)?$profile->wpu_no_auto:''); }}
				</div>
			</div>
			<div class="control-group">
				<label class="control-label" for="fullname">{{ Str::title(__('admin.tagid')->get()) }}</label>
				<div class="controls">
					<!-- {{ Form::xlarge_text('sup_id_pengguna', (Auth::user()->sur_id != 1)?$profile->sup_id_pengguna:''); }} -->
					{{ Form::xlarge_select('sup_id_pengguna', $listID, (Auth::user()->sur_id != 1)?$profile->sup_id_pengguna:''); }}
				</div>
			</div>
		</div>
		<div class="span6">
			<div class="control-group">
				<label class="control-label" for="fullname">{{ Str::title(__('admin.idno')->get()) }}</label>
				<div class="controls">
					{{ Form::xlarge_text('sup_no_ic', (Auth::user()->sur_id != 1)?$profile->sup_no_ic:''); }}
				</div>
			</div>
			<div class="control-group">
				<label class="control-label" for="fullname">Tarikh Dari</label>
				<div class="controls">
					{{ Form::xlarge_text('dateCariMula',date('j-m-Y'), array('id'=>'dateCariMula')); }}
				</div>
			</div>
			<div class="control-group">
				<label class="control-label" for="fullname">Tarikh Hingga</label>
				<div class="controls">
					{{ Form::xlarge_text('dateCariTamat',date('j-m-Y'), array('id'=>'dateCariTamat')); }}
				</div>
			</div>
			<div class="control-group">
				<label class="control-label" for="fullname">Format</label>
				<div class="controls">
					{{ Form::xlarge_select('type', array('html','pdf','xls')); }}
				</div>
			</div>
			<div class="control-group">
				<label class="control-label" for="fullname">&nbsp;</label>
				<div class="controls offset">
					{{ Form::control_group(Form::label('datetill', ''), Form::button('Jana', array('id' => 'generate')).'&nbsp;'.Form::button('Simpan',array('id' => 'print')), ''); }}
				</div>
			</div>
		</div>
	</div>

		</div>
	</div>
	{{ Form::close(); }}
	</div>
</div>

<div class="row-fluids">
	<div class="span12">
		{{ $preview }}
	</div>
</div>

@endsection
@section('scripts')
<script type="text/javascript">

	$(function() {
	  	var checkin = $( "#dateCariMula" ).datepicker({
	      	showWeek: true,
	      	firstDay: 1,
        	format:"d-m-yyyy",
      		autoclose: true,
	    }).on('changeDate', function(ev) {
			  checkin.hide();
		}).data('datepicker');

		var checkout = $('#dateCariTamat').datepicker({
			format:"d-m-yyyy",
		  onRender: function(date) {
		    return date.valueOf() < checkin.date.valueOf() ? 'disabled' : '';
		  }
		}).on('changeDate', function(ev) {
		  checkout.hide();
		}).data('datepicker');

  	});

	

	if({{Auth::user()->sur_id}} == 3){

		$('#genReport [name="wpj_no_auto"]').addClass('disabled').attr('disabled','disabled');
		$('#genReport [name="wpj_no_auto"]').parents('div.control-group').addClass('info');
		$('#genReport [name="wpb_no_auto"]').addClass('disabled').attr('disabled','disabled');
		$('#genReport [name="wpb_no_auto"]').parents('div.control-group').addClass('info');
		$('#genReport [name="wpu_no_auto"]').addClass('disabled').attr('disabled','disabled');
		$('#genReport [name="wpu_no_auto"]').parents('div.control-group').addClass('info');

	}else if({{Auth::user()->sur_id}} == 2 || {{Auth::user()->sur_id}} == 4){

		$('#genReport [name="wjkp_no_auto"]').addClass('disabled').attr('disabled','disabled');
		$('#genReport [name="wjkp_no_auto"]').parents('div.control-group').addClass('info');
		$('#genReport [name="wpj_no_auto"]').addClass('disabled').attr('disabled','disabled');
		$('#genReport [name="wpj_no_auto"]').parents('div.control-group').addClass('info');
		$('#genReport [name="wpb_no_auto"]').addClass('disabled').attr('disabled','disabled');
		$('#genReport [name="wpb_no_auto"]').parents('div.control-group').addClass('info');
		$('#genReport [name="wpu_no_auto"]').addClass('disabled').attr('disabled','disabled');
		$('#genReport [name="wpu_no_auto"]').parents('div.control-group').addClass('info');
		$('#genReport [name="sup_id_pengguna"]').addClass('disabled').attr('disabled','disabled');
		$('#genReport [name="sup_id_pengguna"]').parents('div.control-group').addClass('info');
		$('#genReport [name="sup_no_ic"]').addClass('disabled').attr('disabled','disabled');
		$('#genReport [name="sup_no_ic"]').parents('div.control-group').addClass('info');

	}


	$('#genReport [name="wpj_no_auto"]').change(function() {

		var $eldept =  $('#genReport [name="wpb_no_auto"]');
		var $elunit =  $('#genReport [name="wpu_no_auto"]');

	    $.get("{{ url('administrator/user/divlist') }}",{ id: this.value}, function(data,status){

	    	$eldept.empty();
	        $.each(data, function(key, value) {
				$eldept.append($("<option></option>").attr("value", key).text(value));
	        });
			
	        bahagian = $('#genReport [name="wpb_no_auto"] option').size();

		  	if(bahagian == 1){
		      	$.get("{{ url('administrator/user/unitlist') }}",{ dept:this.value, div:0}, function(data,status){

			        $.each(data, function(key, value) {
						$elunit.append($("<option></option>").attr("value", key).text(value));
			        });
		      	},"json");
		  	}
	    },"json");

	});


	$('#genReport [name="wpb_no_auto"]').change(function() {
		
		var wpj_no_auto = $('#genReport [name="wpj_no_auto"]').val();
		var $elunit =  $('#genReport [name="wpu_no_auto"]');

      	$.get("{{ url('administrator/user/unitlist') }}",{ dept:wpj_no_auto, div:this.value}, function(data,status){

	        $elunit.empty();
	        $.each(data, function(key, value) {
				$elunit.append($("<option></option>").attr("value", key).text(value));
	        });

      	},"json");

	});
	

$('#generate,#print').click(function() {


	$('#genReport [name="wjkp_no_auto"]').removeAttr('disabled');
	$('#genReport [name="wpj_no_auto"]').removeAttr('disabled');
	$('#genReport [name="wpb_no_auto"]').removeAttr('disabled');
	$('#genReport [name="wpu_no_auto"]').removeAttr('disabled');
	$('#genReport [name="sup_id_pengguna"]').removeAttr('disabled');
	$('#genReport [name="sup_no_ic"]').removeAttr('disabled');

	var report = $('#genReport [name="report"]').val();
	var type = $('#genReport [name="type"] option:selected').text();//$('#genReport [name="type"]').val();

	var param = $("#genReport").serialize();
	console.log(type);
	var url = "{{ url('report/jasper/fetch?oper=" + this.id + "&report=" + report + "&ctype=" + type +"&"+ param +"') }}";

	if(report != 0 ){
		
		if(this.id == 'print' || type == 'xls'){
			window.location.href = url;
		}else{
			window.open(url,"","width=800,height=600"); 
		}
		
	}else{

		$('#genReport [name="report"]').parents('div.control-group').addClass('error');

		$('#genReport [name="report"]').focus().addClass('error');
		alert('Jenis Laporan Tidak Dipilih');
	}

});

</script>
@endsection